home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / demos / graphics / xdemo-1.dem < prev    next >
Text File  |  1999-09-16  |  7KB  |  226 lines

  1. function []=xdemo(info,str)
  2. x_message([info;str])
  3. execstr(str)
  4.  
  5.  
  6. function []=xdemo1(filen)
  7. // Demo of graphic primitives
  8. //! 
  9. [lhs,rhs]=argn(0)
  10. if rhs=1,driver("Pos"),xinit(filen);deff('[]=xshow(str)','1');end
  11. xbasc();
  12. plot2d([-100,500],[-100,600],[-1,-1],"022");
  13. deff('[v]=transl(x,t)','v=x+t*ones(x)');
  14. xset("default");
  15. xclip('clipgrf');
  16. x_message(["[I] function to plot a set of objects "]);
  17. expr=['x=0:40:240;';
  18.       'boxes=[x;10*ones(x);30*ones(x);30*ones(x)];';
  19.       'xrects(boxes)'];
  20. xdemo("[I.1] function xrects : plot rectangles",expr);
  21. //
  22. expr=['x=0:40:240;';
  23.       'boxes=[x;45*ones(x);30*ones(x);30*ones(x)];';
  24.       'pats=[0,4,8,12,15,xget(''white''),0];';
  25.       'xrects(boxes,pats);'];
  26. xdemo(" fonction xrects  : filling rectangles",expr);
  27. //
  28. expr=['x=0:40:240;';
  29.       'boxes=[x;90*ones(x);30*ones(x);30*ones(x)];';
  30.       'arcs=[boxes; 0*ones(x);64*180*ones(x)];';
  31.       'pats=[0,4,8,12,15,xget(''white''),0];';
  32.       'xarcs(arcs,pats);'];
  33. xdemo("[I.2] xarcs(arcs,patterns)",expr);
  34. //
  35. expr=['x=0:40:240;';
  36.       'boxes=[x;135*ones(x);30*ones(x);30*ones(x)];';
  37.       'arcs=[boxes; 0*ones(x);64*360*ones(x)];';
  38.       'xarcs(arcs);']
  39. xdemo("[I.2] xarcs(arcs)",expr);
  40. //
  41. expr0=['x1=[0,10,20,30,20,10,0];';
  42.       'y1=[15,30,30,15,0,0,15];y1=160*ones(y1)+y1;';
  43.       'xpols=[x1;transl(x1,40);transl(x1,80);transl(x1,120)'...
  44.       + ';transl(x1,160);transl(x1,200);transl(x1,240)];';
  45.       'ypols=[y1;y1;y1;y1;y1;y1;y1];';
  46.       'xfpolys(xpols'',ypols'');'];
  47. xdemo("[I.3] xfpolys(x,y)",expr0);
  48. //
  49. expr=[ expr0;
  50.       'ypols=transl(ypols,60);';
  51.       'pats=[0,4,8,12,15,xget(''white''),0];';
  52.       'xfpolys(xpols'',ypols'',pats);'];
  53. xdemo("[I.3] xfpolys(x,y,pattern)",expr);
  54. //
  55. expr=[ expr0;
  56.       'ypols=transl(ypols,120);';
  57.       'xpolys(xpols'',ypols'',1:7);'];
  58. xdemo("[I.3] xpolys(x,y,line-style)",expr);
  59. expr=[ expr0;
  60.       'ypols=transl(ypols,180);';
  61.       'xpolys(xpols'',ypols'',-(1:7));'];
  62. xdemo("[I.4] xpolys(x,y,line-style)",expr);
  63. //
  64. expr=['x=0:40:240;';
  65.       'xsegs([x;x+30*ones(x)],[(360+40)*ones(x);(360+70)*ones(x)]);']
  66. xdemo("[I.5] xsegs(x,y)",expr);
  67. //
  68. expr=['x=0:40:240;';
  69.       'xarrows([x;x+30*ones(x)],[(360+70)*ones(x);(360+100)*ones(x)]);'];
  70. xdemo(["[I.6] xarrows(x,y)"],expr);
  71. //
  72. expr=['x=0:100:200;';
  73.       'xnumb(x,500*ones(x),[10,20,35],1);';
  74.       'xnumb(x,550*ones(x),[10,20,35],0);';];
  75. xdemo(["[[II.3] xnumb()"],expr);
  76. xset("default");xclip();
  77. xend();
  78.  
  79.  
  80. function []=xdemo2(filen)
  81. // Demo for graphic primitives
  82. //! 
  83. [lhs,rhs]=argn(0)
  84. if rhs=1,driver("Pos"),xinit(filen);deff('[]=xshow(str)','1');end
  85. xbasc();
  86. xset("default");
  87. plot2d([-100,500],[-100,600],[-1,-1],"022");
  88. xclip('clipgrf');
  89. deff('[v]=transl(x,t)','v=x+t*ones(x)');
  90. x_message(["[II] Basic Functions of drivers :"]);
  91. expr="xrect(20,120,60,60);"
  92. xdemo(["[II.1] xrect : draw one rectangle with current line style"],expr);
  93. expr="xfrect(100,120,60,60);"
  94. xdemo(["[II.1] xfrect : fill one rectangle with current pattern"],expr);
  95. expr="xarc(20,200,50,70,0,64*(225));"
  96. xdemo(["[II.2] xarc : draw part of an elipsis"],expr);
  97. expr="xfarc(100,200,50,70,0,64*225);"
  98. xdemo(["[II.2] xfarc : fill part of an elipsis"],expr);
  99. expr0=["x=0:1:%pi;";
  100.       "[n1,n2]=size(x);";
  101.       "x1=50*sin(x)+40*ones(x);";
  102.       "y1=50*cos(x)+90*ones(x);"];
  103. expr=[expr0;
  104.       "xset(''mark'',6,1);";
  105.       "y1=transl(y1,200);";
  106.       "xpoly(x1,y1,''marks'',0);";
  107.       "xset(''mark'',4,6);";
  108.       "x1=transl(x1,80);";
  109.       "xpoly(x1,y1,''marks'',0);"]
  110. xdemo(["[II.3] xpoly(x,y,""marks"",0)"],expr);
  111. expr=[expr0;"x1=transl(x1,160);";
  112.       "xpoly(x1,y1,''lines'',0);"];
  113. xdemo(["[II.3] xpoly(x,y,""lines"",0)"],expr);
  114. expr=[expr0;"x1=transl(x1,240);";
  115.       "xpoly(x1,y1,''lines'',1);"]
  116. xdemo(["[II.3] xpoly(x,y,""lines"",1)"],expr);
  117. expr=[expr0;"x1=transl(x1,320);";
  118.       "xfpoly(x1,y1,1);"]
  119. xdemo(["[II.4] xfpoly(x,y,1)"],expr);
  120. expr=["xset(''font'',2,2);";
  121.       "xstring(200,200,''Character string'',0,0);";
  122.       "xstring(200,250,''Character string'',0,1);";
  123.       "xstring(400,300,''Chaine '',45,0);"];
  124. xdemo(["[II.5] xstring"],expr);
  125. expr=["rect=xstringl(350,200,''Character string'');";
  126.       "xrect(rect(1),rect(2),rect(3),rect(4));"]
  127. xdemo(["[II.6] xstringl";],expr);
  128. xend();
  129. xset("default");xclip();
  130.  
  131. function []=xdemo3()
  132. // back to gcontext defaults values.
  133. xbasc();
  134. xset("default");
  135. plot2d([-100,500],[-100,600],[-1,-1],"022");
  136. xclip('clipgrf');
  137. deff('[v]=transl(x,t)','v=x+t*ones(x)');
  138. x_message(["[IV] Setting graphic context values"]);
  139. expr=["x=0:0.2:2*%pi;";
  140.       "x1=[sin(x);10*sin(x)];";
  141.       "y1=[cos(x);10*cos(x)];";
  142.       "xsegs(10*x1+200*ones(x1),10*y1+200*ones(y1));"];
  143. xdemo(["[IV.2] segments"],expr);
  144. expr=["xrect(150,460,100,150);";
  145.       "xclip(150,460,100,150);";
  146.       "x=0:0.2:2*%pi;";
  147.       "x1=[sin(x);10*sin(x)];";
  148.       "y1=[cos(x);10*cos(x)];";
  149.       "y1=transl(y1,20);";
  150.       "xsegs(10*x1+200*ones(x1),10*y1+200*ones(y1));";
  151.       "xset(''clipgrf'');";];
  152. xdemo(["[IV.2] segments+clipping zone"],expr);
  153. expr=["xset(''dashes'',1,2,2);";
  154.       "xget(''dashes'',1);";
  155.       "xrect(140,470,120,170);"];
  156. xdemo(["[IV.4] Setting a dash style"],expr);
  157. // 
  158. expr=["xset(''default'');";
  159.       "xset(''font'',2,0);";
  160.       "xstring(0,130,''Scilab'');";
  161.       "xset(''font'',2,1);";
  162.       "xstring(0,150,''Scilab'');";
  163.       "xset(''font'',2,2);";
  164.       "xstring(0,170,''Scilab'');";
  165.       "xset(''font'',2,3);";
  166.       "xstring(0,200,''Scilab'');";
  167.       "xset(''font'',2,4);";
  168.       "xstring(0,230,''Scilab'');";
  169.       "xset(''font'',2,5);";
  170.       "xstring(0,270,''Scilab'');";
  171.       "xset(''font'',3,5);";
  172.       "xstring(0,310,''Scilab'');";
  173.       "xset(''font'',4,5);";
  174.       "xstring(0,350,''Scilab'');"]
  175. xdemo(["[IV.5] Setting font style and size"],expr);
  176. //expr=["xset(''line mode'',1);";
  177. //      "xpoly([300,80,0,-80,0],[100,0,80,0,-80],''lines'',0);"];
  178. //xdemo(["[IV.6] Relative line mode for drawing functions"],expr);
  179. expr=["xset(''line mode'',0);";
  180.       "xlfont(''-*-helvetica-bold-r-normal--*-%s0-*-*-p-*-*-1'',6);";
  181.       "xset(''font'',6,3);";
  182.       "xstring(100,260,''helVB'',0,1);"];
  183. xdemo(["[IV.7] Loading a new font hlevB is now font 6"],expr);
  184. //
  185. expr0=["x1=[350,400,450];";
  186.       "[n1,n2]=size(x1);";
  187.       "y1=300*ones(x1);"];
  188. expr=[expr0;
  189.       "xset(''mark'',6,2);";
  190.       "xpoly(x1,y1,''marks'',0);"];
  191. xdemo(["[IV.8] changing current mark"],expr);
  192. expr=[expr0;
  193.       "xset(''mark'',7,2);";
  194.       "xpoly(x1,y1+50*ones(x1),''marks'',0);";
  195.       "xset(''mark'',8,3);";
  196.       "xpoly(x1,y1+100*ones(x1),''marks'',0);"];
  197. xdemo(["[IV.8] changing current mark"],expr);
  198. expr=["xset(''thickness'',5);";
  199.       "xrect(400,200,50,100);";];
  200. xdemo(["[IV.9] Thickness)"],expr);
  201. xset("default");
  202. expr=["xfrect(400,50,50,100);";
  203.       "xclea(410,50,10,100);"];
  204. xdemo(["[V.2] Clear a rectangle"],expr);
  205. xend();
  206. xset("default");
  207. xclip();
  208.  
  209. function []=xdemo4(display)
  210. [lhs,rhs]=argn(0)
  211. if rhs=0,display="unix:0.0",end
  212. xbasc();
  213. xset("default");
  214. plot2d([-100,500],[-100,600],[-1,-1],"022");
  215. plot3d();
  216. x_message(["[V] General functions"]);
  217. expr=["xinit(display);";
  218.       "plot2d()";];
  219. xdemo(["[V.1] Creating a new window"],expr);
  220. expr=["xset(''window'',0);";
  221.       "xselect();";]
  222. xdemo("[V.2] Selecting and raising window 0]",expr);
  223. xend();
  224. xset("default");
  225.  
  226.